<?php
class RecordsController extends EavAppController {

	var $name = 'Records';
	var $helpers = array('Html', 'Form', 'Eav.Grid');
	var $uses = array();
	
	function checkEntity($entity)
	{
		
	}
	
	function _getModel($entity)
	{
		$this->Model = ClassRegistry::init($entity);
	}
	
	function index()
	{
		if(!empty($this->data))
		{
			prd($this->data);
		}
		$entity = 'Jerks.Jerk';
		$this->_getModel($entity);
		$this->set('entity', 'Jerk');
		
		//prd($this->Model->find('all', array('eav'=>true)));
		//prd($this->Model);
		$this->paginate[$this->Model->alias]['eav'] = true;
		$this->paginate[$this->Model->alias]['limit'] = 10;
		$this->set('items', $this->paginate($this->Model));
		$this->set('modelAlias', $this->Model->alias);
		//prd($this->Model);
		//$fieldsToShow = array_merge();
		//$this->set('gridFields');
		$this->set('modelObj', $this->Model);
	}
	
	function view($id = false)
	{
		$entity = 'Jerks.Jerk';
		$this->_getModel($entity);
		$this->set('entity', 'Jerk');
		
		$this->set('modelAlias', $this->Model->alias);
		$this->set('modelObj', $this->Model);		
		
		$this->set('item', $this->Model->find('first', array('conditions'=>array('id'=>$id), 'eav'=>true)));
	}
	
	function test()
	{
		$entity = 'Jerks.Jerk';
		$this->_getModel($entity);		
		
		$conditions = array(
					   'OR' => array(
					      array('field_1' => 'manu'),
					      array('field_1' => 'shriti')
					   ),
					   'AND' => array(
					      array('field_1' => 'manu')
					   ),
					);
		
		//$conditions = array('field_1'=>'sdd');
		
		$eav = true;
		$results = $this->Model->find('all', compact('conditions','eav'));
		prd($results);
	}
}
?>
